﻿using System;
using Conv.MnistReader;

namespace Conv
{
    class Program
    {
        static void Main(string[] args)
        {
            TeachConvNet90(20);
            //TestWeight();
        }
        static void TestWeight()
        {
            Weight[] testW = new Weight[10];
            for (int i = 0; i < 10; i++)
                testW[i] = new Weight();
            for (int i = 0; i < 10; i++)
                Console.Write("{0}\t", testW[i].Value);
        }
        static void TeachConvNet()//What about epohs???
        {
            ConvNet net = new ConvNet();
            double[,] img = new double[28, 28];
            ImageReader ImgR = new ImageReader("train-images.idx3-ubyte");
            LableReader lableR = new LableReader("train-labels.idx1-ubyte");
            int correct = 0;
            int rightNums = 0;
            for (int i = 0; i < 60000; i++)
            {

                ImgR.GetImage(out img);
                correct = lableR.GetLabel();
                if (net.Process(img) == correct)
                    rightNums++;

                net.Teach(correct);
                if (i % 1000 == 0)
                {
                    Console.WriteLine("Right: {0}, At 1000", rightNums);
                    rightNums = 0;
                }

            }
            Console.WriteLine("Done! \n Out: {0}", net.Process(img));
        }
        static void TeachConvNet90(int EpohCount)//What about epohs???
        {
            Console.WriteLine("start builting");
            ConvNet90 net = new ConvNet90();
            double[,] img = new double[28, 28];
            Console.WriteLine("start caching");
            ImageReader ImgR = new ImageReader("train-images.idx3-ubyte");
            LableReader lableR = new LableReader("train-labels.idx1-ubyte");
            Console.WriteLine("Finish caching");
            int correct = 0;
            int rightNums = 0;
            for (int k = 0; k < EpohCount; k++)
            {
                ImgR.NewEpoh();
                lableR.NewEpoh();
                for (int i = 0; i < 20000; i++)
                {

                    ImgR.GetImage(out img);
                    correct = lableR.GetLabel();
                    if (net.Process(img) == correct)
                        rightNums++;
                    net.Teach(correct);
                    if (i % 1000 == 0)
                    {
                        Console.WriteLine("Right: {0}, At 1000", rightNums);
                        rightNums = 0;
                    }
                }
                Console.WriteLine("Done! \n Out: {0}", net.Process(img));
            }
        }

    }
}
